package es.javamyadmin.servlet;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import es.javamyadmin.dao.TriggersDAO;
import es.javamyadmin.pojo.Mensaje;

/**
 * Servlet que elimina un trigger
 * @author Emilio Javier Castillo Gonzalez
 * @author Hector Delgado Duran
 */
public class TriggerEditor extends HttpServlet {
   
	/**
	 * 
	 */
	private static final long serialVersionUID = -5746678693017304940L;

	/**
	 * Metodo que elimina un trigger
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String user = request.getParameter("user");
		String database = request.getParameter("database");
		String pass = request.getParameter("pass");
		String host = request.getParameter("host");
		String port = request.getParameter("port");
		String accion = request.getParameter("accion");
		InputStream path = getServletContext().getResourceAsStream("/WEB-INF/properties/mensajes.properties");
		boolean todoBien = false;
		if(accion.equals("delete")){
			String nombreTri = request.getParameter("trigger");
			TriggersDAO tri = new TriggersDAO();
			todoBien = tri.deleteTrigger(database, user, pass, host, port, nombreTri);
			if(todoBien){
				request.setAttribute("ok", Mensaje.getMensaje(path, "5006"));
			}
			else{
				request.setAttribute("ko", Mensaje.getMensaje(path, "0"));
			}
			
		}
		request.getRequestDispatcher("/jsp/triggers-bd.jsp").forward(request,response);
		
	}

}
